package com.dosen.api.thought.core.service.entity;

import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.annotation.*;
import com.dosen.api.base.common.asserts.AssertNP;
import com.dosen.api.base.common.utils.information.JSONUtil;
import com.dosen.api.base.common.utils.information.TimeUtil;
import com.dosen.api.thought.common.model.valobj.ConsciousnessEnvironment;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Date;

/**
 *
 *
 * @author zhanggc
 * @email zhangguangcheng@beyondcent.com
 * @date 2023-01-24 15:05:19
 */
@Data
@TableName("dosen_search_consciousness")
@Accessors(chain = true)
public class SearchConsciousnessEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 *
	 */
	@TableId
	private Long id;
	/**
	 *
	 */
	private String name;
	/**
	 * 别名
	 */
	private String alias;
	/**
	 *
	 */
	private String description;
	/**
	 * 产生这个意识的背景环境描述，有格式要求
	 * @see ConsciousnessEnvironment
	 */
	private String environment;
	/**
	 * 权重：查询，更新有结果后权重+1
	 */
	private Long weight;
	/**
	 *
	 */
	@TableField(fill = FieldFill.INSERT)
	private Integer isDeleted;
	/**
	 *
	 */
	@Version
	@TableField(fill = FieldFill.INSERT)
	private Long version;
	/**
	 *
	 */
	@TableField(fill = FieldFill.INSERT)
	private String createdBy;
	/**
	 *
	 */
	@TableField(fill = FieldFill.INSERT)
	private Date createdTime;
	/**
	 *
	 */
	@TableField(fill = FieldFill.INSERT_UPDATE)
	private String updatedBy;
	/**
	 *
	 */
	@TableField(fill = FieldFill.INSERT_UPDATE)
	private Date updatedTime;

	/**
	 * 获取意识环境描述对象
	 *
	 * @return
	 */
	public ConsciousnessEnvironment consciousnessEnvironment() {
		if (!AssertNP.legalParams(environment)) {
			return new ConsciousnessEnvironment();
		}
		ConsciousnessEnvironment item = JSONUtil.getT(environment, new TypeReference<ConsciousnessEnvironment>() {
		});
		Date date = item.getDate();
		long millis = TimeUtil.getDateTime(date).getMillis();
		item.setTime(millis);
		LocalDateTime localDateTime = TimeUtil.getLocalDateTime(millis);
		item.setLocalDateTime(localDateTime);
		return item;
	}
}
